<template>
	<view class="home">
		<view class="text-32 text-bold">灯号</view>
		<view class="bg-ff bg-shadow padding-30 radius-40 margin-top-25 text-28">
			{{code}}号（自动获取）
		</view>
		<view class="text-32 text-bold margin-top-40">下单人信息</view>
		<view class="bg-ff bg-shadow padding-30 radius-40 margin-top-25">
			<input type="text" placeholder="请输入" class="text-28" />
		</view>
		<view class="text-32 text-bold margin-top-40">请核对商品清单</view>
		<view class="bg-ff bg-shadow padding-30 radius-40 margin-top-25" v-if="name">
			<view class="flex margin-bottom-25">
				<image :src="image" mode="" class="listimg"></image>
				<view class="flex-one margin-left-30">
					<view class="text-28 height-60 line-30 text-cut-two">{{name}}</view>
					<view class="flex align-center margin-top-40">
						<view class="text-red text-28 flex-one">￥{{price}}</view>
						<view class="text-28">数量：{{num}}</view>
					</view>
				</view>
			</view>
			<view class="text-28 text-right">
				小计： <text class="text-red">￥{{num*price}}</text>
			</view>
		</view>
		<view class="bg-ff bg-shadow padding-30 radius-40 margin-top-25" v-else>
			<view class="flex margin-bottom-25" v-for="(item,index) in carlist" :key="index">
				<image :src="item.product.image" mode="" class="listimg"></image>
				<view class="flex-one margin-left-30">
					<view class="text-28 height-60 line-30 text-cut-two">{{item.product.name}}</view>
					<view class="flex align-center margin-top-40">
						<view class="text-red text-28 flex-one">￥{{item.product.price}}</view>
						<view class="text-28">数量：{{item.num}}</view>
					</view>
				</view>
			</view>
			<view class="text-28 text-right">
				小计： <text class="text-red">￥{{money}}</text>
			</view>
		</view>
		<view class="text-28 margin-top-30">待桌游结束后—起买单</view>
		<view class="subbtn" @click="getOrder">确定点单</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				code: "",
				carlist: [],
				money: "",
				order_id: "",
				product_id: "",
				spec_id: "",
				num: "",
				name:"",
				image:"",
				price:""
			}
		},
		onLoad(options) {
			console.log(options)
			this.order_id = options.id
			if(options.name){
				this.name = decodeURIComponent(options.name)
				this.image = decodeURIComponent(options.image)
				this.product_id = options.proudid
				this.num = options.num
				this.spec_id = options.spec_id
				this.price = options.price
			}
		},
		onReady() {
			this.rq.getData('shop/light_code', {
				light_id: uni.getStorageSync('lampid')
			}).then(res => {
				if (res.code == 1) {
					this.code = res.data.code
				}
			})
			this.rq.getData('Products/Cart_list',{
				occupants_id:this.order_id
			}).then(res => {
				if (res.code == 1) {
					this.carlist = res.data
					this.money = res.money
				}
			})
		},
		methods: {
			getOrder() {
				this.rq.getData('Products/add_good_order', {
					occupants_id: this.order_id,
					product_id: this.product_id,
					spec_id: this.spec_id,
					num: this.num,
					occupants_id:this.order_id
				}).then(res => {
					if (res.code == 1) {
						this.cn.alert('下单成功').then(res => {
							uni.navigateBack({
								delta: 2
							})
						})
					}
				})
			}
		}
	}
</script>

<style>
	.home {
		width: 100%;
		min-height: 100vh;
		background: #fff;
		padding: 20rpx 30rpx;
	}

	.listimg {
		width: 172rpx;
		height: 172rpx;
		border-radius: 16rpx;
	}

	.subbtn {
		width: 100%;
		height: 88rpx;
		background: #101010;
		box-shadow: 0rpx 16rpx 80rpx 0rpx rgba(66, 66, 67, 0.25);
		border-radius: 200rpx 200rpx 200rpx 200rpx;
		font-weight: bold;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		margin: 166rpx auto;
	}
</style>